<?php
/**
 * 产品提货
 * (model)
 */
namespace App\Models\ProductPickup;

use App\Models\Basics\SysArea;
use App\Models\Product\ProductClassify;
use App\Models\Product\ProductSku;
use Illuminate\Database\Eloquent\Model;

class PickupOrder extends Model{

    protected $table = 'product_pickup_order';

    protected $guarded = [];


    const STATUS_NO  = 0; //未申请(初始状态)
    const STATUS_YES = 1; //申请中
    const STATUS_CANCEL    = 2; //撤回申请
    const STATUS_SUCCESS   = 3; //审核通过
    const STATUS_REJECT    = 4; //审核驳回
    const STATUS_CONFIRM   = 5; //已确认
    /**
     * 申请状态
     * @var string[]
     */
    public static $APPLY_STATUS = [
        self::STATUS_NO   => '未申请',
        self::STATUS_YES  => '申请中',
        self::STATUS_CANCEL     => '撤回申请',
        self::STATUS_SUCCESS    => '审核通过',
        self::STATUS_REJECT     => '审核驳回',
        self::STATUS_CONFIRM    => '已确认',
    ];

    /**
     * 地区
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function area(){
        return $this->belongsTo(SysArea::class,'area_id');
    }

    /**
     * sku
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function sku(){
        return $this->belongsTo(ProductSku::class,'psku_id');
    }
    /**
     * classify
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function classify(){
        return $this->belongsTo(ProductClassify::class,'classify_id');
    }

    public function skuClassify(){
        return $this->hasOneThrough(
            ProductClassify::class,
            ProductSku::class,
            'id',//中间表
            'id',//目标表
            'psku_id',//当前模型
            'classify_id'//中间表
        );
    }

}
